using UnityEngine;

namespace BasicScript.Component
{
	public class BreathObject : MonoBehaviour
	{
		private SpriteRenderer sprite;

		private float time;

		private bool isBreath;

		public bool isRandom = true;

		public float delayTime;

		public float intervalTime;

		private void Start()
		{
			sprite = base.transform.GetComponent<SpriteRenderer>();
			if (isRandom)
			{
				time = ResetTime();
			}
			else
			{
				time = delayTime;
			}
		}

		private void LateUpdate()
		{
			if (isBreath)
			{
				time += Time.deltaTime;
				if (time < 1f)
				{
					sprite.color = new Color(1f, 1f, 1f, 1f - time);
					return;
				}
				if (time < 2f)
				{
					sprite.color = new Color(1f, 1f, 1f, time - 1f);
					return;
				}
				sprite.color = new Color(1f, 1f, 1f, 1f);
				isBreath = false;
				time = ResetTime();
			}
			else
			{
				time -= Time.deltaTime;
				if (time <= 0f)
				{
					time = 0f;
					isBreath = true;
				}
			}
		}

		private float ResetTime()
		{
			if (isRandom)
			{
				return Random.Range(2, 5);
			}
			return intervalTime;
		}
	}
}
